package com.codewsq.pool;

import com.google.gson.Gson;
import jdk.nashorn.internal.runtime.options.LoggingOption;
import redis.clients.jedis.Jedis;

import java.util.ArrayList;
import java.util.List;

public class ThreadPoolUtilTest {

    public static void main(String[] args) {
        //连接本地的 Redis 服务
        Jedis jedis = new Jedis("localhost", 6379);
        // 如果 Redis 服务设置了密码，需要下面这行，没有就不需要
        jedis.auth("suoma123");
        System.out.println("连接成功");
        //查看服务是否运行
        System.out.println("服务正在运行: " + jedis.ping());

        List<User> userList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            User user = new User();
            user.setUsername("zhangsan" + i);
            user.setPassword("123456" + i);
            user.setAge(20 + i);
            userList.add(user);
        }

        for (int i = 0; i < userList.size(); i++) {
            User user = userList.get(i);
            ThreadPoolUtil.getThreadPool().execute(() -> {
                System.out.println((user.getUsername() + " : " + user.toString()));
            });
        }

    }
}
